import Vue from "vue";

import App from "./App.vue";

import VueRouter from "vue-router";
import Layout from "./Layout.vue";
Vue.use(VueRouter);
// window.username='jack';
// Vue.prototype.username = "lili";
// 状态管理
const stroe = new Vue({
  data() {
    return { count: 100 };
  },
  methods: {
    add(x, y) {
      return x + y;
    },
  },
});
Vue.prototype.mystroe = stroe;

const router = new VueRouter({
  mode: "hash",
  routes: [
    {
      path: "/home",
      name: "Home",
      component: Layout,
      redirect: { name: "HomeIndex" },
      children: [
        {
          path: "index",
          name: "HomeIndex",
          component: () => import("./HomeIndex.vue"),
        },
      ],
    },
    {
      path: "/shop",
      name: "Shop",
      component: Layout,
      redirect: { name: "ShopIndex" },
      meta: {
        cnName: "商城",
      },
      children: [
        {
          path: "index",
          name: "ShopIndex",
          meta: {
            cnName: "商城首页",
          },
          component: () => import("./ShopIndex.vue"),
        },
        {
          path: "detail",
          name: "ShopDetail",
          meta: {
            cnName: "商品详情",
          },
          component: () => import("./ShopDetail.vue"),
        },
        {
          path: "list",
          name: "ShopList",
          meta: {
            cnName: "商品列表",
          },
          component: () => import("./ShopList.vue"),
        },
      ],
    },
    {
      path: "/user",
      name: "User",
      component: Layout,
      redirect: { name: "UserIndex" },
      meta: {
        cnName: "用户",
      },
      children: [
        {
          path: "index",
          name: "UserIndex",
          meta: {
            cnName: "用户首页",
          },
          component: () => import("./UserIndex.vue"),
        },
      ],
    },
  ],
});

new Vue({
  render: (h) => h(App),
  router, //路由注入
}).$mount("#app");
